package com.learn.controller;

import com.learn.base.ApiResult;
import com.learn.base.ApiResultUtils;
import com.learn.base.R;
import com.learn.dto.system.req.SysLoginReq;
import com.learn.dto.system.resp.SysLoginResp;
import com.learn.service.SysLoginService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <一句话功能简述> <功能详细描述>
 *
 * @author yaoqihui
 * @version 2025/3/26
 * @see [相关类/方法]
 * @since [learn-platform]
 */
@Slf4j
@RestController
@RequestMapping ("/admin/v1/tokens")
@RequiredArgsConstructor
public class SysLoginController
{
	private final SysLoginService sysLoginService;

	@PostMapping ("login")
	public ApiResult<SysLoginResp> login (@RequestBody @Validated SysLoginReq sysLoginReq)
	{
		R<SysLoginResp> loginResp = sysLoginService.loginPassword (sysLoginReq.getAccount (),
				sysLoginReq.getPassword (), sysLoginReq.getChannel ());
		return ApiResultUtils.build (loginResp.getResultCode (), loginResp.getResultMsg (), loginResp.getData ());
	}
}